home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-02
/
prodpack.zip
/
DB4PPSRC.EXE
/
SCR2PRG.PRG
< prev
next >
Wrap
Text File
|
1993-05-11
|
16KB
|
615 lines
*' $Header: $
PROCEDURE Scr2Prg
PARAMETERS pcPara1, pcPara2, pcPara3, pcPara4
*----------------------------------------------------------------------------
* NAME
* Scr2Prg -
*
* DESCRIPTION
*
* PARAMETERS
* pcScr = Name of SCR file used to make a dialog box
*
*----------------------------------------------------------------------------
SET SAFETY OFF
SET TALK OFF
SET STATUS OFF
SET CURSOR OFF
SET CLOCK ON
SET FULLPATH ON
SET EXACT ON
SET PATH TO \test\ccppdbb\dbos, \test\ccppdbb\prgs, \test\ccppprgs\dbos, \test\ccppprgs\prgs
IF LEFT( OS(), 3 ) = "DOS"
lc_slash = "\"
ELSE
lc_slash = "/"
ENDIF
cDboDir = ""
cPrgDir = ""
cScrDir = ""
cScr2Gen = ""
cCurDir = SET( "DIRECTORY" )
DO CASE
CASE RIGHT( cCurDir,7 ) = "CCPPDBB"
PUBLIC DBW_HELP
DBW_HELP = "DBBHELP"
CASE RIGHT( cCurDir,8 ) = "CCPPMFFU"
PUBLIC DBW_HELP
DBW_HELP = "MFFUHELP"
ENDCASE
*-- Scan arguments
nArgs = PCOUNT()
n = 1
DO WHILE n <= nArgs .AND. n <= 4
cnVar = STR( n, 1 )
cArg = UPPER( pcPara&cnVar. )
DO CASE
CASE LEFT( cArg, 2 ) = "-D" && DBO Directory
nComma = AT( ",", cArg )
IF nComma > 0
cDboDir = LTRIM( TRIM( SUBSTR( cArg, nComma + 1 ) ) )
ELSE
cDboDir = LTRIM( TRIM( SUBSTR( cArg, 3 ) ) )
ENDIF
IF RIGHT( cDboDir, 1 ) <> lc_Slash
cDboDir = cDboDir + lc_Slash
ENDIF
CASE LEFT( cArg, 2 ) = "-P" && PRG Directory
nComma = AT( ",", cArg )
IF nComma > 0
cPrgDir = LTRIM( TRIM( SUBSTR( cArg, nComma + 1 ) ) )
ELSE
cPrgDir = LTRIM( TRIM( SUBSTR( cArg, 3 ) ) )
ENDIF
IF RIGHT( cPrgDir, 1 ) <> lc_Slash
cPrgDir = cPrgDir + lc_Slash
ENDIF
CASE LEFT( cArg, 2 ) = "-S" && PRG Directory
nComma = AT( ",", cArg )
IF nComma > 0
cScrDir = LTRIM( TRIM( SUBSTR( cArg, nComma + 1 ) ) )
ELSE
cScrDir = LTRIM( TRIM( SUBSTR( cArg, 3 ) ) )
ENDIF
IF RIGHT( cScrDir, 1 ) <> lc_Slash
cScrDir = cScrDir + lc_Slash
ENDIF
OTHERWISE && File list of PRGs
cScr2Gen = LTRIM( TRIM( cArg ) )
ENDCASE
n = n + 1
ENDDO
*-------------------------
*-- Validate DBO Directory
*-------------------------
IF .NOT. ISBLANK( cDboDir )
fhCheckIt = 0
fhCheckIt = FCREATE( cDboDir + "CHECHIT.OUT" )
IF fhCheckIt > 0
IF FCLOSE( fhCheckIt )
cFullPath = LEFT( cDboDir, LEN( cDboDir ) - 1 )
SET DIRECTORY TO &cFullPath
ERASE CHECHIT.OUT
cDboDir = SET( "DIRECTORY" )
SET DIRECTORY TO &cCurDir
ENDIF
ELSE
cMsg = [DBO Directory does not exist:] + cDboDir
? cMsg
! ECHO &cMsg.
QUIT WITH 1
ENDIF
ELSE
cDboDir = SET( "DIRECTORY" )
ENDIF
*-------------------------
*-- Validate PRG Directory
*-------------------------
IF .NOT. ISBLANK( cPrgDir )
fhCheckIt = 0
fhCheckIt = FCREATE( cPrgDir + "CHECHIT.OUT" )
IF fhCheckIt > 0
IF FCLOSE( fhCheckIt )
cFullPath = LEFT( cPrgDir, LEN( cPrgDir ) - 1 )
SET DIRECTORY TO &cFullPath
ERASE CHECHIT.OUT
cPrgDir = SET( "DIRECTORY" )
SET DIRECTORY TO &cCurDir
ENDIF
ELSE
cMsg = [PRG Directory does not exist:] + cPrgDir
? cMsg
! ECHO &cMsg.
QUIT WITH 1
ENDIF
ELSE
cPrgDir = SET( "DIRECTORY" )
ENDIF
*-------------------------
*-- Validate SCR Directory
*-------------------------
IF .NOT. ISBLANK( cScrDir )
fhCheckIt = 0
fhCheckIt = FCREATE( cScrDir + "CHECHIT.OUT" )
IF fhCheckIt > 0
IF FCLOSE( fhCheckIt )
cFullPath = LEFT( cScrDir, LEN( cScrDir ) - 1 )
SET DIRECTORY TO &cFullPath
ERASE CHECHIT.OUT
cScrDir = SET( "DIRECTORY" )
SET DIRECTORY TO &cCurDir
ENDIF
ELSE
cMsg = [PRG Directory does not exist:] + cScrDir
? cMsg
! ECHO &cMsg.
QUIT WITH 1
ENDIF
ELSE
cScrDir = SET( "DIRECTORY" )
ENDIF
*-----------------------------------
*-- Make sure SCR to generate exists
*-----------------------------------
IF ISBLANK( cScr2Gen )
cMsg = [No SCR file to generate. Quitting with no error.]
? cMsg
! ECHO &cMsg.
QUIT WITH 0
ENDIF
IF .NOT. ( ":" $ cScr2Gen .OR. lc_Slash $ cScr2Gen )
cScr2Gen = cScrDir + lc_Slash + cScr2Gen
ENDIF
cFullPre = cScr2Gen
IF .NOT. ( "." $ cScr2Gen )
cScr2Gen = cScr2Gen + ".scr"
ELSE
DO _FullPre WITH cFullPre
ENDIF
gn_OdMax = 4
gn_OdCur = 0
gn_OdLeft = 0
gn_OdRight = 0
gc_OdText = [Creating file for generation: ] + cFullPre
gc_OdBoxCl = ""
DO _Odomet
SET DIRECTORY TO &cScrDir
cScrRoot = _FileRoot( cScr2Gen)
DEXPORT SCREEN ( cScrRoot)
gn_OdCur = gn_OdCur + 1
DO _Odomet
pnGenCode = DGEN( "SCR2DBF.GEN", cScrRoot + ".SNL" )
ERASE cScrRoot + ".SNL"
ERASE scr2dbf.dbo
ERASE cDboDir + lc_Slash + cScrRoot + ".dbo"
ERASE cDboDir + lc_Slash + cScrRoot + ".win"
COMPILE Scr2Dbf
gn_OdCur = gn_OdCur + 1
DO _Odomet
DO Scr2Dbf WITH _TmpName( ".DBF" )
cDbf = DBF()
USE ( cDbf ) ALIAS &cScrRoot. NOSAVE
gn_OdCur = gn_OdCur + 1
DO _Odomet
ERASE scr2dbf.prg
ERASE scr2dbf.dbo
DO MakeItEz WITH cScrRoot
gn_OdCur = gn_OdCur + 1
DO _Odomet
DO GroupObj
gn_OdCur = gn_OdCur + 5
DO _Odomet
DO GenCode WITH cScrRoot
CLOSE DATABASE
lCompileOk = .T.
IF .NOT. FILE( cScrRoot + ".dbo" )
ERASE cScrRoot + ".err"
SET ALTERNATE TO cScrRoot + ".err"
SET ALTERNATE ON
SET TALK ON
SET CONSOLE ON
ON ERROR lCompileOk = .F.
COMPILE cScrRoot + ".prg"
ON ERROR
SET ALTERNATE OFF
SET ALTERNATE TO
SET TALK OFF
SET CONSOLE OFF
ENDIF
IF lCompileOk
ERASE cScrRoot + ".err"
*------------------------------------------
*-- Move the resulting program files around
*------------------------------------------
IF cScrDir <> cDboDir
cSource = cFullPre + ".dbo"
! COPY &cSource. &cDboDir
ERASE ( cSource )
ENDIF
IF cScrDir <> cPrgDir
cSource = cFullPre + ".prg"
! COPY &cSource. &cPrgDir
ERASE ( cSource )
ENDIF
cQCode = 0
ELSE
cQCode = 1
ENDIF
SET DIRECTORY TO &cCurDir
QUIT WITH cQCode
*-- EOP: Scr2Prg WITH pcScr
FUNCTION _TmpName && Returns a pseudo-random file root name
PARAMETER pc_ext
*--------------------------------------------------------------------
* NAME
* _TmpName - Returns a pseudo-random file root name.
*
* SYNOPSIS
* _TmpName( [.ext] )
*
* DESCRIPTION
* _TMPNAME() returns an pseudo-random string of
* digits suitable for use as a temporary file name.
* Eight digits (sometimes fewer) are returned.
* Successive calls to _TMPNAME() can be used to
* generate a series of unique file names.
*
* An optional file extension can be passed as an
* argument. If this is done, _TMPNAME will make
* sure that the file name it returns does not already
* exist within the current dBASE path setting.
*
* If either the DBTMP or TMP DOS environment variables
* are set, _TMPNAME() will use its value for a path
* prefix. If both are set, the DBTMP value is used.
*
* PARAMETERS
* pc_ext - optional file name extension. May optionally
* start with a ".", followed by up to three characters.
* (Note that some characters are not allowed in file names,
* depending on the specific operating system in use.)
*
* EXAMPLE
*
* lc_tmpfile = _TMPNAME(".TMP")
* * Possible return value: "87113336.TMP"
* USE master
* COPY TO (lc_tmpfile)
* * The file "87113336.TMP" would now exist
*
* LIMITATIONS
* If _TMPNAME() is used without the extension
* parameter, the FILE() function can be used to
* make certain that a created file name does not
* already exist.
*
* _TMPNAME() assumes the extension argument has
* only characters allowed in filenames.
*
* Note also that leading 0's will not be returned.
* If you desire exactly eight digits, this line:
* TRANSFORM( RAND(-1) * 100000000, "@L 99999999" )
* returns a random string of digits that is always
* eight characters long.
*
* SEE ALSO:
* RAND(), FILE()
*
*--------------------------------------------------------------------
PRIVATE lc_env, lc_ext, lc_prefix, lc_root, lc_slash, ;
ll_err, lh_chkit
IF LEFT( OS(), 3 ) = "DOS"
lc_slash = "\"
ELSE
lc_slash = "/"
ENDIF
lh_chkit = 0
lc_env = GETENV( "DBTMP" )
IF .NOT. ISBLANK( lc_env )
ll_err = .F.
ON ERROR ll_err = .T.
lc_prefix = IIF( RIGHT( lc_env, 1 ) = lc_slash, lc_env, lc_env + lc_slash )
lh_chkit = FCREATE( lc_prefix + [CHECKIT.OUT] )
IF lh_chkit > 0
IF FCLOSE( lh_chkit )
ERASE ( lc_prefix + [CHECKIT.OUT] )
ENDIF
ELSE
lc_env = ""
ll_err = .F.
ENDIF
ON ERROR
ENDIF
IF ISBLANK( m->lc_env )
lc_env = GETENV( "TMP" )
IF .NOT. ISBLANK( lc_env )
ll_err = .F.
ON ERROR ll_err = .T.
lc_prefix = IIF( RIGHT( lc_env, 1 ) = lc_slash, lc_env, lc_env + lc_slash )
lh_chkit = FCREATE( lc_prefix + [CHECKIT.OUT] )
IF lh_chkit > 0
IF FCLOSE( lh_chkit )
ERASE ( lc_prefix + [CHECKIT.OUT] )
ENDIF
ELSE
lc_env = ""
ll_err = .F.
ENDIF
ON ERROR
ENDIF
IF ISBLANK( m->lc_env )
lc_prefix = ""
ELSE
lc_prefix = IIF( RIGHT( lc_env, 1 ) = lc_slash, lc_env, lc_env + lc_slash )
ENDIF
ELSE
lc_prefix = IIF( RIGHT( lc_env, 1 ) = lc_slash, lc_env, lc_env + lc_slash )
ENDIF
IF PCOUNT() = 0
lc_root = m->lc_prefix + LTRIM( STR( RAND( -1 ) * 100000000, 8 ) )
RETURN( lc_root )
ELSE
IF .NOT. "." $ m->pc_ext
lc_ext = "." + m->pc_ext
ELSE
lc_ext = m->pc_ext
ENDIF
lc_ext = SUBSTR(m->lc_ext, 1, 4)
DO WHILE .T.
lc_root = LTRIM( STR( RAND( -1 ) * 100000000, 8 ) )
IF .NOT. FILE( m->lc_prefix + m->lc_root + m->lc_ext )
RETURN( m->lc_prefix + m->lc_root + m->lc_ext )
ENDIF
ENDDO
ENDIF
*-- EOF: _TmpName( [.ext] )
FUNCTION _FWrite0
PARAMETERS ph_file, pn_nulls
*--------------------------------------------------------------------
* NAME
* _FWrite0 - Write number of CHR(0)s to open file.
*
* SYNOPSIS
* _FWrite0( ph_file, pn_nulls )
*
* DESCRIPTION
* _FWrite0 will write out to an open file handle <ph_file>,
* <pn_nulls> null characters ( 00h ). This is useful since
* REPLICATE() currently does not support CHR(0).
*
* PARAMETERS
* ph_file - numeric file handle of the target file.
* pn_nulls - number of CHR(0)s to output.
*
* EXAMPLE
* * Write 100 nulls to the start of "MYFILE.TXT":
* lh_file = FOPEN( "MYFILE.TXT", "rw" )
* ln_var = FWrite0( lh_file, 100 )
* ln_mem = FCLOSE( "MYFILE.TXT" )
*
* SEE ALSO
* FOPEN(), FWRITE()
*--------------------------------------------------------------------
PRIVATE ln_count, ln_chrs
ln_count = 1
DO WHILE m->ln_count <= m->pn_nulls
ln_chrs = FWRITE( m->ph_file, CHR(0) )
ln_count = m->ln_count + 1
ENDDO
RETURN( m->pn_nulls )
*-- EOF: _FWrite0( ph_file, pn_nulls )
FUNCTION _MakeExte
PARAMETER pc_fname
*--------------------------------------------------------------------
* NAME
* _MAKEEXTE - Creates a dBASE IV structure extended
* file.
*
* SYNOPSIS
* _MAKEEXTE( pc_fname )
*
* DESCRIPTION
* The _MAKEEXTE() function creates an empty dBASE IV
* structure extended file. It uses low-level file
* I/O functions to write the structure directly to
* disk. This file can then be used to create
* other database files.
*
* _MAKEEXTE() will return .T. if the filename was
* created, otherwise .F. If no file extension is
* specified, ".DBF" is assumed.
*
* Be warned that if a file with the same name
* already exists, it will be automatically
* overwritten.
*
* PARAMETER
* pc_fname - the name of the new structure extended
* file to create.
*
* EXAMPLE
*
* * Create a new .DBF with a single field:
* IF _MAKEEXTE( "custtemp" )
* USE custtemp
* APPEND BLANK
* REPLACE field_name WITH "LAST_NAME",;
* field_type WITH "C",;
* field_len WITH 30,;
* field_idx WITH "Y"
* CREATE newdbf FROM custtemp
* ELSE
* ? "Error: Custtemp.dbf not created"
* ENDIF
*
* DEPENDENCIES
* _MAKEEXTE() uses the _FWRITE0 function.
*
* LIMITATIONS
* _MAKEEXTE() expects that TALK is OFF
*
* SEE ALSO:
* COPY STRUCTURE EXTENDED
*
*--------------------------------------------------------------------
PRIVATE lc_newdbf, lh_newdbf, ll_result, ln_bytes
ll_result = .F.
lc_newdbf = LTRIM( RTRIM( pc_fname ) )
IF TYPE('lc_newdbf') = "C" .AND. ( .NOT. ISBLANK( lc_newdbf ) )
lc_newdbf = IIF( .NOT. "." $ lc_newdbf, lc_newdbf, ;
SUBSTR(lc_newdbf, 1, AT(".", lc_newdbf) - 1)) + ".DBF"
lh_newdbf = 0
IF DISKSPACE() < 5000
DEACTIVATE WINDOW _plswait && Deactivate _PlsWait window
DO _Err_Box WITH [Insufficient disk space]
IF LASTKEY() = 28
DO _Helpsys WITH "_FXZERR", "NODISK"
ENDIF
ELSE
lh_newdbf = FCREATE( lc_newdbf, "rw" )
ENDIF
IF lh_newdbf > 0
*-- .dbf with no memos
ln_bytes = FWRITE( lh_newdbf, CHR(3) )
*-- date of last update
ln_bytes = FWRITE( lh_newdbf, ;
CHR( YEAR( DATE() ) - 1900 ) + CHR( MONTH( DATE() ) )+;
CHR( DAY( DATE() ) ) )
*-- No records yet
ln_bytes = _FWRITE0( lh_newdbf, 4 )
*-- Number of bytes in header.
ln_bytes = FWRITE( lh_newdbf, CHR(193) )
ln_bytes = FWRITE( lh_newdbf, CHR(0) )
*-- Number off bytes in each records
ln_bytes = FWRITE( lh_newdbf, CHR(19) )
ln_bytes = FWRITE( lh_newdbf, CHR(0) )
*-- Fill other dbf header stuff
ln_bytes = _FWRITE0( lh_newdbf, 20 )
*-- Write out the extended structure.
ln_bytes = FWRITE( lh_newdbf, "FIELD_NAME" )
ln_bytes = FWRITE( lh_newdbf, CHR(0) )
ln_bytes = FWRITE( lh_newdbf, "C" )
ln_bytes = _FWRITE0( lh_newdbf, 4 )
ln_bytes = FWRITE( lh_newdbf, CHR(10) )
ln_bytes = _FWRITE0( lh_newdbf, 15 )
ln_bytes = FWRITE( lh_newdbf, "FIELD_TYPE" )
ln_bytes = FWRITE( lh_newdbf, CHR(0) )
ln_bytes = FWRITE( lh_newdbf, "C" )
ln_bytes = _FWRITE0( lh_newdbf, 4 )
ln_bytes = FWRITE( lh_newdbf, CHR(1) )
ln_bytes = _FWRITE0( lh_newdbf, 15 )
ln_bytes = FWRITE( lh_newdbf, "FIELD_LEN" )
ln_bytes = _FWRITE0( lh_newdbf, 2 )
ln_bytes = FWRITE( lh_newdbf, "N" )
ln_bytes = _FWRITE0( lh_newdbf, 4 )
ln_bytes = FWRITE( lh_newdbf, CHR(3) )
ln_bytes = _FWRITE0( lh_newdbf, 15 )
ln_bytes = FWRITE( lh_newdbf, "FIELD_DEC" )
ln_bytes = _FWRITE0( lh_newdbf, 2 )
ln_bytes = FWRITE( lh_newdbf, "N" )
ln_bytes = _FWRITE0( lh_newdbf, 4 )
ln_bytes = FWRITE( lh_newdbf, CHR(3) )
ln_bytes = _FWRITE0( lh_newdbf, 15 )
ln_bytes = FWRITE( lh_newdbf, "FIELD_IDX" )
ln_bytes = _FWRITE0( lh_newdbf, 2 )
ln_bytes = FWRITE( lh_newdbf, "C" )
ln_bytes = _FWRITE0( lh_newdbf, 4 )
ln_bytes = FWRITE( lh_newdbf, CHR(1) )
ln_bytes = _FWRITE0( lh_newdbf, 15 )
*-- Write the field (header) terminator
ln_bytes = FWRITE( lh_newdbf, CHR(13) )
IF FCLOSE( lh_newdbf )
ll_result = .T.
ENDIF
ENDIF && Could not create DBF skeleton
ENDIF && Parameters not correct
RETURN( ll_result )
*-- EOF: _MakeExte( pc_fname )
*'----------------------------------------------------------------------------
*' $Log: $
*'----------------------------------------------------------------------------